package com.sj;

import com.sj.anno.User;
import com.sj.anno.UserService;
import com.sj.aop.Book;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestAnno {

    @Test
    public void testAop() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean3.xml");
        Book book = (Book) context.getBean("book");
        System.out.println(book);
        //com.sj.aop.Book@48f2bd5b
        //com.sj.aop.Book@43814d18（去掉aop）
        System.out.println(book.getClass().getName());
        //com.sj.aop.Book$$EnhancerBySpringCGLIB$$144b35fa
        //com.sj.aop.Book（去掉aop）
        book.add();
    }

    @Test
    public void testService() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        UserService userService = (UserService) context.getBean("userService");
        userService.add();
    }

    @Test
    public void testUser() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        User user = (User) context.getBean("user");
        System.out.println(user);
        user.add();
        Object o = context.getBean("user");
        System.out.println(o);
        Object o2 = context.getBean("user");
        System.out.println(o2);
    }
}
